$(function(){

    //footer
    var footer ={
        menuData :{},//菜单数据
    };
    /***
     *  构建二级菜单
     *  */
    footer.initSecondMenu = function( htmlDiv,menuData ){
        var navDiv ='';
        if( menuData !=undefined && menuData.authCode !='pro'){
            if( menuData.childMenu.length > 0){
                $.each(menuData.childMenu,function(index,obj){
                    navDiv +='<li><a href="'+obj.link+'" title="'+obj.name+'">'+obj.name+'</a></li>';
                });
            }
        }
        //产品列表展示不一样
        if( menuData !=undefined && menuData.authCode =='pro'){
            if( menuData.childMenu.length > 0){
                $.each(menuData.childMenu,function(index,obj){
                    navDiv +='<li><a href="/web/productByTags?type='+obj.id+'" title="'+obj.name+'">'+obj.name+'</a></li>';
                    /*$.each(obj.childMenu,function(i,tag){
                        navDiv +='<li><a href="/web/productExhibition?tagId='+tag.id+'">'+tag.name+'</a></li>';
                    });*/
                });
            }
        }

       return navDiv;
}
    /**
     * 初始化构建首页导航菜单
     */
    footer.initMenu = function(){
        //获取菜单div
        var $menu = $("#foot-link");
        $.ajax({
            async: false,
            url: '/web/findIndexMenu',
            success: function (result){
                if (result && result.code == 200) {
                    var data = result.data;
                    //循环获取菜单列表
                    var itemMenuDiv ='';
                    $.each( data ,function (index,obj) {
                        if( obj.authCode !='index' ){
                            itemMenuDiv +='<div class="foot-link"><h3>'+obj.name+'</h3><ul>';
                            //获取二级菜单
                            itemMenuDiv += footer.initSecondMenu(itemMenuDiv,obj);
                            itemMenuDiv +='</ul></div>';
                        }
                        footer.menuData[obj.authCode] = obj;
                    })
                    $menu.empty().append( itemMenuDiv );
                    /*$menu.find('li').on('click',function(){//构建二级菜单
                        var authCode = $(this).find("a").attr("name");
                        //
                        $menu.find('li a').removeClass("main-menu-btn-af");
                        $(this).find("a").addClass("main-menu-btn-af");
                        if( authCode!=undefined && authCode !=''){
                            header.initSecondMenu(header.menuData[authCode]);
                        }
                    });*/
                }
            },
            error: function () {
                layer.alert('服务器出错啦！', {icon: 2, title: '错误'});
            }
        });
    };

    //初始化
    footer.initMenu();
});